package com.adtec.yxdemo.filelanding;

import com.adtec.yxdemo.filelanding.service.YxFileComService;
import com.adtec.yxdemo.filelanding.service.YxPayInfoFileService;
import com.adtec.yxdemo.utils.FileEncUtil;
import com.adtec.yxdemo.utils.FileLandUtil;
import com.jfinal.aop.Inject;
import org.apache.log4j.Logger;

import java.io.File;

/**
 * 文件处理对外类
 */
public class FileLandService {
    private static Logger logger = Logger.getLogger(FileLandService.class); // 获取logger实例
    String fileName = "D:\\001\\003\\001003" + FileLandUtil.getDate() + ".tar.gz";
    String keySavePath = "D:\\001\\003";
    @Inject
    YxPayInfoFileService yxPayInfoFileService;
    @Inject
    YxFileComService fileComService;

    public void creatFile() {
        File file = new File("D:\\001\\003");
        if (!file.exists()) {
            file.mkdir();
        }
        yxPayInfoFileService.saveYxPayInfo();
        yxPayInfoFileService.savaYxOrderDetails();
        yxPayInfoFileService.savaYxDetails();
        yxPayInfoFileService.saveYxPayTrack();
        try {
            fileComService.FilePack();
        } catch (Exception e) {
            logger.warn("文件压缩失败");
        }
        try {
            FileEncUtil.getKeyAndSave(keySavePath);
        } catch (Exception e) {
            logger.warn("生成公钥失败");
        }
        try {
            FileEncUtil.encryptFile(fileName);
        } catch (Exception e) {
            logger.warn("文件加密失败");
        }

    }
}
